$(document).ready(function(){
	$('.add').hide();
	$(".header").load("header.html");$(".footer").load("footer.html"); 
})
function add(){
	if($('.add').css("display")=='none')
		$('.add').show();
	else
		$('.add').hide();
	
}
function add_exit(){
	$('.add').hide();
}



  
  var myModule = angular.module('myModule', []);
  
  
  
  myModule.controller('MyController', function ($scope, $http,$location) {
      $scope.items =null;
      $scope.reply = null;
      $scope.id='';
      $scope.writeReply={};
      $scope.modifyReply={};
      $scope.user={};
      
      $scope.subject=null;
      $scope.modify=false;
      
      $scope.selectedIndex=-1;
      $scope.files=[];
      $scope.loadData = function() {
          myUtil.onHttp($http, 'get', 'user.do', null, null, function(data){$scope.id=data;});
          myUtil.onHttp($http,'get','userAuthority.do',null,null,function(data){$scope.user=data});
    	  myUtil.onHttp($http, 'get', 'content.do', {content_id:$location.search().content_id}, null, function(data) {$scope.items=data.content; $scope.reply =data.reply; $scope.subject=data.subject} )
    	  myUtil.onHttp($http,'get','fileList.do',{content_id:$location.search().content_id},null,function(data){
    		  $scope.files=data;
    	  })
      }

      $scope.list = function(){
    	  location.href='notice.html#?pg='+$location.search().pg+"&title="+$location.search().title+"&subject="+$location.search().subject+"&search="+$location.search().search;
    	  
      }
      
      $scope.replyWrite = function(){
    	  $scope.writeReply.content_id=$location.search().content_id;
    	  $scope.writeReply.id=$scope.id;
    	 
    	  
    	  myUtil.onHttp($http, 'post', 'replyWrite.do',null,$scope.writeReply,function(){$scope.loadData(); $scope.writeReply.content=''});
      }
      
      $scope.replyDelete = function(index){
    	  
    	  myUtil.onHttp($http, 'post', 'replyDelete.do',{reply_id : $scope.reply[index].reply_id , content_id:$location.search().content_id},null, $scope.loadData);
      }
      
      $scope.modify =function(index,content){
    	  $scope.selectedIndex=index;
    	  $scope.modifyReply.content=content;
      }
      
      $scope.init=function(){
    	  $scope.selectedIndex=-1;
      }
      
      $scope.replyModify=function(reply_id){
    	  $scope.modifyReply.reply_id=reply_id;
    	  
    	  myUtil.onHttp($http, 'post', 'replyModify.do',null,$scope.modifyReply,function(){$scope.loadData(); $scope.modifyReply.content=''; $scope.selectedIndex=-1; });
      }
      
      $scope.download=function(id){
    	  location.href="fileDownload.do?id="+id;
      }
      
     

      $scope.loadData();        
  });